<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="__PUBLIC__/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="__PUBLIC__/font-awesome/css/font-awesome.min.css" media="all"/>
    <link rel="stylesheet" href="__CSS__/admin.css" media="all">
</head>
<body style="padding:10px;">
<div class="tplay-body-div">

    <form class="layui-form" id="admin">
        <div class="layui-form-item">
            <label class="layui-form-label">新版本号</label>
            <div class="layui-input-block">
                <input type="hidden" name="id" id="id" placeholder="请输入id" value="" class="layui-input">
                <input type="text" name="appversion" lay-verify="appversion" autocomplete="off" placeholder="请输入新版本号" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">版本说明</label>
            <div class="layui-input-block">
                <textarea name="version_release" placeholder="请输入版本说明" class="layui-textarea"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">强制更新</label>
            <div class="layui-input-block">
                <input type="radio" name="mandatory" value="false" title="否" checked="">
                <input type="radio" name="mandatory" value="true" title="是">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">APK文件</label>
            <div class="layui-input-block" style="width:220px">
                <button type="button" class="layui-btn" id="test-upload-normal">上传APK</button>
                <div class="layui-upload-list">
                    <input type="hidden" name="app_download" id="app_download" lay-verify="app_download" autocomplete="off" placeholder="请上传APK文件" class="layui-input">
                    <p id="test-upload-demoText"></p>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">热更文件</label>
            <div class="layui-input-block" style="width:220px">
                <button type="button" class="layui-btn" id="test1-upload-normal">上传WGT文件</button>
                <div class="layui-upload-list">
                    <input type="hidden" name="hot_download" id="hot_download" lay-verify="hot_download" autocomplete="off" placeholder="请上传热更WGT文件" class="layui-input">
                    <p id="test1-upload-demoText"></p>
                </div>
            </div>
        </div>
        <input type="hidden" name="appid" value="{$usid}">
        <button class="layui-btn" lay-submit lay-filter="admin">立即提交</button>
        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </form>


    <script src="__PUBLIC__/layui/layui.js"></script>
    <script src="__PUBLIC__/jquery/jquery.min.js"></script>
    <script>
        layui.use('upload', function () {
            var upload = layui.upload;
            //执行实例
            var uploadInst = upload.render({
                elem: '#test-upload-normal' //绑定元素
                , url: "{:url('common/upload')}" //上传接口
                , data: {use: 'article_thumb'}
                ,exts: 'apk'
                , done: function (res) {
                    //上传完毕回调
                    if (res.code == 2) {
                        //$('#demo1').attr('src', res.src);
                        document.getElementById("app_download").value = res.id;
                        layer.msg('上传成功');
                        //$('#app_download').append('<input type="hidden" name="app_download" value="' + res.id + '">');
                    } else {
                        layer.msg(res.msg);
                    }
                }
                , error: function () {
                    //请求异常回调
                    //演示失败状态，并实现重传
                    var demoText = $('#demoText');
                    demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
                    demoText.find('.demo-reload').on('click', function () {
                        uploadInst.upload();
                    });
                }
            });
            var uploadInst = upload.render({
                elem: '#test1-upload-normal' //绑定元素
                , url: "{:url('common/upload')}" //上传接口
                , data: {use: 'article_thumb'}
                ,exts: 'wgt'
                , done: function (res) {
                    //上传完毕回调
                    if (res.code == 2) {
                        //$('#demo1').attr('src', res.src);
                        document.getElementById("hot_download").value = res.id;
                        layer.msg('上传成功');
                        //$('#app_download').append('<input type="hidden" name="app_download" value="' + res.id + '">');
                    } else {
                        layer.msg(res.msg);
                    }
                }
                , error: function () {
                    //请求异常回调
                    //演示失败状态，并实现重传
                    var demoText = $('#demoText');
                    demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
                    demoText.find('.demo-reload').on('click', function () {
                        uploadInst.upload();
                    });
                }
            });
        });
    </script>
    <script>
        layui.use(['layer', 'form'], function () {
            var layer = layui.layer,
                $ = layui.jquery,
                form = layui.form;
            $(window).on('load', function () {
                form.on('submit(admin)', function (data) {
                    $.ajax({
                        url: "{:url('admin/app_system/vsadd')}",
                        data: $('#admin').serialize(),
                        type: 'post',
                        async: false,
                        success: function (res) {
                            if (res.code == 1) {
                                layer.alert(res.msg, function (index) {
                                    location.href = res.url;
                                })
                            } else {
                                layer.msg(res.msg);
                            }
                        }
                    })
                    return false;
                });
            });
        });
    </script>

</div>
</body>
</html>